package com.xunbao.thread.util;

import java.util.concurrent.*;

/**
 * Created with IntelliJ IDEA.
 * ClassName:MyTaskWithResult
 * Description:
 * Author:yijiawei
 * Date: 2016/5/30 9:58
 */
public class MyTaskWithResult implements Callable {

    private String name;

    public MyTaskWithResult(String name) {
        this.name = name;
    }

    @Override
    public ResultObject call() throws Exception {

        TimeUnit.SECONDS.sleep(5);

        ResultObject resultObject = null;
        for (int i = 0; i < 3; i++) {
            System.out.println("MyTaskWithResult - name=" + name + ",i=" + i);
        }
        if ("two".equals(name)) {
            resultObject = new ResultObject(false, "A001", "name is error");
        } else {
            resultObject = new ResultObject(true);
        }
        return resultObject;
    }

}
